package com.cy.sc.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.ZonedDateTime;
/**
 * <br>@class: MyGatewayConfig
 * <br>@description: 代码配置方式实现路由规则
 * <br>@author: cy
 * <br>@date: 2020-04-11 22:45:21
 * <br>@version: 1.0
 * <br>
 * <br>@since: (版本) 作者 时间 注释
 */
@Configuration
public class MyGatewayConfig {

    @Bean
    public RouteLocator myRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        //匿名函数r
        //格式：
        //( parameters ) -> { statements; }
        routes.route("route_consumer_100",
                r -> r.path("/consumer/staff/get/**")
                        .uri("http://localhost:8080")).build();
        //使用function中的参数
        routes.route("route_baidu1",
                predicateSpec -> predicateSpec.path("/guonei")
                                .uri("http://news.baidu.com")).build();

        return routes.build();
    }
    public static void main(String[] args) {
        ZonedDateTime now = ZonedDateTime.now();
        System.out.println("now = " + now);
    }
}
